/* 正在进行 */
<template>
  <div>
    <Card :bordered="false" v-if="isShow">
      <p slot="title">正在进行</p>
      <p>
        <Row style="padding:10px 0">
          <Col span="8" offset="16">
          <Input search v-model="searchButVal" enter-button="搜索" placeholder="请输入关键字" @on-search="searchBut" />
          </Col>
        </Row>
        <Row>
          <Col span="24">
          <Table border :columns="columns" :data="listData" height="500"></Table>
          </Col>
        </Row>
        <Row v-if="hidePage" style="padding:10px 0">
          <Col span="24">
          <Page style="float:right" :total="total" @on-change="changePage" show-total />
          </Col>
        </Row>
      </p>
    </Card>
    <card :bordered="false" v-else>
      <p slot="title">
        <Row style="padding-bottom: 10px" :gutter="32">
          <Col span="2">
          <h4>项目流程单</h4>
          </Col>
          <Col span="2" style="color:#999" @click.native="isShow = true"> 返回>>
          </Col>
        </Row>
      </p>
      <table width="100%" cellpadding="0" cellspacing="0" border="1">
        <tr>
          <th colspan="4">项目流程单</th>
        </tr>
        <tr>
          <th>流程</th>
          <th>操作</th>
          <th>操作记录</th>
          <th>功能</th>
        </tr>
        <tr>
          <td rowspan="2" width="25%">创建项目</td>
          <td width="25%">保存</td>
          <td width="25%">2018-07-31 9:30</td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printProject" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="createProgram" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">资料收集</td>
          <td width="25%">保存</td>
          <td width="25%"> </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printCollect" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="dataCollection" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">现场勘探</td>
          <td width="25%">保存</td>
          <td width="25%"> </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printSurver" :Project_id="routerId">></PrintButton>
            <ButtonShow style="display:inline-block" rName="reconnaissanceTrip" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">环境质量及监测</td>
          <td width="25%">保存</td>
          <td width="25%"></td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printMonitor" :Project_id="routerId">></PrintButton>
            <ButtonShow style="display:inline-block" rName="environmentQuality" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">报告编制及审核</td>
          <td width="25%">保存</td>
          <td width="25%">
          </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printAudit" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="reportTria" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">报告送审</td>
          <td width="25%">保存</td>
          <td width="25%">
          </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printAudit" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="reportTria" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">技术评估</td>
          <td width="25%">保存</td>
          <td width="25%">
          </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printAppraise" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="technologyAssessment" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">报告报批</td>
          <td width="25%">保存</td>
          <td width="25%">
          </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printBatch" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="reportApproval" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">报告公示</td>
          <td width="25%">保存</td>
          <td width="25%">
          </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printPublicShow" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="reportPublicity" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2" width="25%">报告存档</td>
          <td width="25%">保存</td>
          <td width="25%">
          </td>
          <td rowspan="2">
            <PrintButton style="display:inline-block" Url="print/printArchives" :Project_id="routerId"></PrintButton>
            <ButtonShow style="display:inline-block" rName="reportArchives" :Project_id="routerId"></ButtonShow>
          </td>
        </tr>
        <tr>
          <td>提交</td>
          <td></td>
        </tr>
      </table>
    </card>
  </div>
</template>

<script>
  import {
    getTypeInfo
  } from '../../libs/status'
  export default {
    props: {
      hidePage: {
        default: true,
      }
    },
    data() {
      return {
        searchButVal: "",
        routerId: '',
        isShow: true,
        total: 0,
        page: 1,
        columns: [{
            align: "center",
            title: '项目编号',
            key: 'project_number',
            sortable: true
          },
          {
            align: "center",
            title: '项目名称',
            key: 'project_name'
          },
          {
            align: "center",
            title: '建设单位',
            key: 'build_unit',
            sortable: true
          },
          {
            align: "center",
            title: '类型',
            key: 'report_type',
            sortable: true
          },
          {
            align: "center",
            title: '修改日期',
            key: 'perject_time',
            sortable: true
          },
          {
            align: "center",
            title: '状态',
            key: 'perject_type_name',
            sortable: true
          },
          {
            align: "center",
            title: '操作',
            key: 'operation',
            render: (h, params) => {
              return h("div", [
                h(
                  "Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    style: {
                      marginRight: "5px",
                      color: "#ffffff",
                      background: "#2996ff",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        this.routerId = params.row.id
                        this.isShow = false
                      }
                    }
                  },
                  "查看"
                ),
                h(
                  "Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    style: {
                      marginRight: "5px",
                      color: "#ffffff",
                      background: "#2996ff",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        switch (params.row.perject_type) {
                          case '6':
                            var Atype = 0
                            break;
                          case '7':
                            var Atype = 1
                            break;
                          case '8':
                            var Atype = 2
                            break;
                          case '9':
                            var Atype = 3
                            break;
                          case '10':
                            var Atype = 4
                            break;
                        }

                        this.show(params.index, params.row.id, Atype, params.row.perject_type);
                      }
                    }
                  },
                  "修改"
                )
              ])
            }
          },
        ],
        listData: [],
      }
    },
    created() {
      /* 调取正在进行接口 */
      this.getUnderway(this.page)
    },
    methods: {
      searchBut() {
        this.getUnderway(1)
      },
      show(index, Project_id, Atype, Perject_type) {
        let info = this.listData[index],
          projectId = info.id
        // 跳转到相关页面
        let name = getTypeInfo(info.perject_type, 'route')
        this.$router.push({
          name,
          query: {
            Project_id,
            Atype,
          }
        })
      },
      getUnderway(page) {
        let Project_name = this.searchButVal

        axios.get('/projectInformation/findWithState', {
          params: {
            pageIndex: page - 1,
            Project_name,
          }
        }).then(res => {
          if (res._STATUS) {
            
            // 格式化数据
            res.projectInfo.forEach((e, i) => {
              switch (e.perject_type) {
                case "1":
                  e['perject_type_name'] = "创建项目"
                  e['perjectR_type'] = "createProgram"
                  break;
                case "2":
                  e['perject_type_name'] = "资料收集"
                  e['perjectR_type'] = "dataCollection"
                  break;
                case "3":
                  e['perject_type_name'] = "现场勘探"
                  e['perjectR_type'] = "reconnaissanceTrip"
                  break;
                case "4":
                  e['perject_type_name'] = "环境质量"
                  e['perjectR_type'] = "environmentQuality"
                  break;
                case "5":
                  e['perject_type_name'] = "报告编制"
                  e['perjectR_type'] = "reportReview"
                  break;
                case "6":
                  e['perject_type_name'] = "分公司一审"
                  e['perjectR_type'] = "firstInstance"
                  break;
                case "7":
                  e['perject_type_name'] = "分公司二审"
                  e['perjectR_type'] = "secondInstance"
                  break;
                case "8":
                  e['perject_type_name'] = "初审"
                  e['perjectR_type'] = "firstTrial"
                  break;
                case "9":
                  e['perject_type_name'] = "复审"
                  e['perjectR_type'] = "reExamine"
                  break;
                case "10":
                  e['perject_type_name'] = "终审"
                  e['perjectR_type'] = "lastInstance"
                  break;
                case "11":
                  e['perject_type_name'] = "报告送审"
                  e['perjectR_type'] = "reportTria"
                  break;
                case "12":
                  e['perject_type_name'] = "技术评估"
                  e['perjectR_type'] = "technologyAssessment"
                  break;
                case "13":
                  e['perject_type_name'] = "报告报批"
                  e['perjectR_type'] = "reportApproval"
                  break;
                case "14":
                  e['perject_type_name'] = "报告公示"
                  e['perjectR_type'] = "reportPublicity"
                  break;
                case "15":
                  e['perject_type_name'] = "报告存档"
                  e['perjectR_type'] = "reportArchives"
                  break;
                case "16":
                  e['perject_type_name'] = "项目结束"
                  e['perjectR_type'] = "underway"
                  break;
              }

            });
          } else {
            res.count = 0
            res.projectInfo = []
          }

          this.total = res.count
          this.listData = res.projectInfo
        })
      },
      changePage(page) {
        this.getUnderway(page)
      },
      getInfo(id) {
        console.log(id);
        axios.get('/projectInformation/findProjectByID', {
          params: {
            id,
          }
        }).then(res => {
          this.$store.commit('setProjectInfo', res.info)
        })
      }
    }
  }
</script>

<style scoped>
  .ivu-col-span-2:hover {
    cursor: pointer;
  }
</style>